<?php
if (!defined('WEB_ROOT')) {
	exit;
}
$GLOBALS['curtlang']==""?$get_current_lang='en-US':$get_current_lang=$GLOBALS['curtlang'];
if (isset($_GET['catId']) && (int)$_GET['catId'] >= 0) {
	$catId = (int)$_GET['catId'];
	$queryString = "&catId=$catId";
} else {
	$catId = 0;
	$queryString = '';
}
// for paging
// how many rows to show per page
$rowsPerPage = 10;

$sql = "SELECT cat_id, cat_parent_id, cat_name, cat_name_vi, cat_description,cat_description_vi, cat_image
        FROM tbl_category
		WHERE cat_parent_id = $catId
		ORDER BY cat_name";
$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage);

?>

<form action="processCategory.php?action=addCategory" method="post"
	name="frmListCategory" id="frmListCategory">
<table width="100%" border="1" align="center" cellpadding="2"
	cellspacing="1" class="text">
	<tr align="center">
		<td>Category</td>
		<td>Description</td>
		<td width="75">Image</td>
		<td width="4"></td>
		<td width="75">Modify</td>
		<td width="75">Delete</td>
		<tr height="2"></tr>
		<?php
		$cat_parent_id = 0;
		if (dbNumRows($result) > 0) {
			$i = 0;
			while($row = dbFetchAssoc($result)) {
				extract($row);
				$get_cat_name=$get_current_lang=="en-US"? $cat_name: $cat_name_vi;
				if ($i%2) {
					$class = 'row1';
				} else {
					$class = 'row2';
				}

				$i += 1;

				if ($cat_parent_id == 0) {					
					$cat_name = "<a href=\"index.php?catId=$cat_id\">$get_cat_name</a>";
				}
				else 
				{
					$cat_name= "<a href=\"#\">$get_cat_name</a>";
				}

				if ($cat_image) {
					$cat_image = WEB_ROOT . '/images/category/' . $cat_image;
				} else {
					$cat_image = WEB_ROOT . '/images/no-image-small.png';
				}
				?>
		<tr class="<?php echo $class; ?>">
			<td><img alt="" src="../images/maik.gif"><a></a> <?php 
				echo   $cat_name;
			?></td>
			<td><?php 
			echo $get_cat_name=$get_current_lang=="en-US"?  nl2br($cat_description):  nl2br($cat_description_vi);
			?></td>
			<td width="75px" align="center"><img src="<?php echo $cat_image; ?>"></td>
			<td width="2"></td>
			<td width="75" align="center"><a
				href="javascript:modifyCategory(<?php echo $cat_id; ?>);"><img
				src="../images/icons/pencil.png" alt="Edit" /></a></td>
			<td width="75" align="center"><a
				href="javascript:deleteCategory(<?php echo $cat_id; ?>);"><img
				src="../images/icons/cross.png" alt="Delete" /></a></td>
		</tr>
		<?php
			} // end while
			?>
		<tr>
			<td colspan="5" align="center"><?php 
			echo $pagingLink;
			?></td>
		</tr>
		<?php
		} else {
			?>
		<tr>
			<td colspan="5" align="center">No Categories Yet</td>
		</tr>
		<?php
		}
		?>
		<tr>
			<td colspan="5"></td>
		</tr>
		<tr>
			<td colspan="5" align="right"><input name="btnAddCategory"
				type="button" id="btnAddCategory" value="Add Category"
				class="graybutton" onClick="addCategory(<?php echo $catId; ?>)"></td>
		</tr>

</table>



</form>
